<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>06 类式组件</title>
</head>

<body>
    <div id="root"></div>
</body>

<script src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>

<script type="text/babel">
    class HelloMessage extends React.Component {
        render() {
            return (
                <div>
                    <h1>Hello {this.props.name} {this.props.isOk ? '好' : '不好'}</h1>
                </div>
            )
        }
    }

    class App extends React.Component {
        constructor(props) {
            super(props)
            this.state = { isReact: true }

            this.onChangeIsReact = this.onChangeIsReact.bind(this)
        }

        onChangeIsReact() {
            // 无法修改state状态
            // this.state.isReact = !this.state.isReact

            this.setState({ isReact: !this.state.isReact })
        }

        render() {
            return (
                <div>
                    <HelloMessage name="Tom" isOk={true} />
                    <HelloMessage name="Jerry" isOk={false} />

                    <h3 onClick={this.onChangeIsReact}>isReact：{this.state.isReact ? '是' : '否'}</h3>
                </div>
            )
        }
    }

    const root = ReactDOM.createRoot(document.getElementById('root'))
    root.render(<App />) 
</script>

</html>